package cn.ahxb.frame.work.ui.home.fragments;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.ahxb.frame.R;
import cn.ahxb.frame.common.adapter.BaseRecyclerAdapter;
import cn.ahxb.frame.common.adapter.SmartViewHolder;
import cn.ahxb.frame.common.utils.ToastHelper;

public class HomePage1Fragment extends Fragment {

    private int mTitleBarHeight;
    private boolean mIsTitleBgTranslucent;

    @BindView(R.id.rv_toast)
    RecyclerView mRecyclerView;

    public HomePage1Fragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View layout = inflater.inflate(R.layout.fragment_home_page1, container, false);
        ButterKnife.bind(this, layout);
        return layout;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        List<String> stringList = new ArrayList<>();
        stringList.add("normal toast");
        stringList.add("success toast");
        stringList.add("warn toast");
        stringList.add("error toast");
        mRecyclerView.setAdapter(new BaseRecyclerAdapter<String>(stringList, android.R.layout.simple_list_item_1, new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        ToastHelper.getInstance(getActivity()).showNormal("成功了成功了成功了成功了成功了成功了");
                        break;
                    case 1:
                        ToastHelper.getInstance(getActivity()).showSucceed("成功了成功了成功了成功了成功了成功了");
                        break;
                    case 2:
                        ToastHelper.getInstance(getActivity()).showWarn("警告你警告你警告你警告你");
                        break;
                    case 3:
                        ToastHelper.getInstance(getActivity()).showError("出错了出错了出错了");
                        break;
                }
            }
        }) {
            @Override
            protected void onBindViewHolder(SmartViewHolder holder, String model, int position) {
                holder.text(android.R.id.text1, model);
            }
        });
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
    }
}
